package com.youyi.yyviewsdklibrary.View;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lkx.liandianqinew.R;

public class MyImgTextView extends LinearLayout {
    private ImageView mImg;
    private onItemClickListener mOnItemClickListener;
    private TextView mTitle;

    public interface onItemClickListener {
        void onClick(View view);
    }

    public MyImgTextView(Context context) {
        super(context);
    }

    public void setOnItemClickListener(onItemClickListener onitemclicklistener) {
        this.mOnItemClickListener = onitemclicklistener;
    }

    public MyImgTextView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MyImgTextView);
        String string = obtainStyledAttributes.getString(R.styleable.MyImgTextView_y_text);
        int resourceId = obtainStyledAttributes.getResourceId(R.styleable.MyImgTextView_y_img, R.drawable.view_icon);
        int color = obtainStyledAttributes.getColor(R.styleable.MyImgTextView_y_imgColor, 0);
        int color2 = obtainStyledAttributes.getColor(R.styleable.MyImgTextView_y_tvColor, 0);
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_img_text, (ViewGroup) this, true);
        this.mImg = (ImageView) inflate.findViewById(R.id.v_yimg);
        this.mTitle = (TextView) inflate.findViewById(R.id.v_ytv);
        this.mImg.setImageResource(resourceId);
        if (color != 0) {
            try {
                this.mImg.setColorFilter(color);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (color2 != 0) {
            try {
                this.mTitle.setTextColor(color2);
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        this.mTitle.setText(TextUtils.isEmpty(string) ? "标题" : string);
        inflate.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.MyImgTextView.AnonymousClass1 */

            public void onClick(View view) {
                if (MyImgTextView.this.mOnItemClickListener != null) {
                    MyImgTextView.this.mOnItemClickListener.onClick(view);
                }
            }
        });
    }

    public void setTitle(String str) {
        TextView textView = this.mTitle;
        if (textView != null) {
            textView.setText(str);
        }
    }

    public void setImg(int i) {
        ImageView imageView = this.mImg;
        if (imageView != null) {
            imageView.setImageResource(i);
        }
    }
}
